package com.yunda.AJDeviceService.utils;


import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 * Created by JinHu on 2022/10/26 12:01
 */
public class PictureUtils {

    public final static PictureUtils pictureUtil = new PictureUtils();

    private PictureUtils() {
    }

    public static PictureUtils getInstance() {
        return pictureUtil;
    }


    /**
     * 将图片保存到指定位置
     *
     * @param image        缓冲文件类
     * @param fileLocation 文件位置
     */
    public static void createImage(BufferedImage image, String fileLocation, String fileName)  {
        File file = new File(fileLocation);
        if (!file.exists()) {
            file.mkdirs();
        }
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(fileLocation + fileName);
            ImageIO.write(image, "jpg", fos);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

   


}
